<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: VGA/MouseOnScreen/MouseOnScreen.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_v_g_a_2_mouse_on_screen_2_mouse_on_screen_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">VGA/MouseOnScreen/MouseOnScreen.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>PS/2 mouse and mouse pointer on screen</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="classfabgl_1_1_v_g_a_controller.html">fabgl::VGAController</a> DisplayController;</div><div class="line"><a name="_a1"></a><a class="code" href="classfabgl_1_1_canvas.html">fabgl::Canvas</a>        canvas(&amp;DisplayController);</div><div class="line"><a name="_a2"></a><a class="code" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a> PS2Controller;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> indicatorX = 300;</div><div class="line"><span class="keywordtype">int</span> indicatorY = 170;</div><div class="line"><span class="keywordtype">int</span> cursor     = 0;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> showCursorPos(MouseStatus <span class="keyword">const</span> &amp; status)</div><div class="line">{</div><div class="line">  canvas.setPenColor(<a name="a3"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div><div class="line">  canvas.setBrushColor(<a name="a4"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1cabf28513245738599d13e3ce36bd16c82">Color::Yellow</a>);</div><div class="line">  canvas.drawTextFmt(indicatorX, indicatorY, <span class="stringliteral">&quot; %d %d &quot;</span>, status.X, status.Y);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  DisplayController.begin();</div><div class="line">  DisplayController.<a name="a5"></a>setResolution(<a name="a6"></a><a class="code" href="fabglconf_8h_ae913dffdd13bd77b79d1a253e88bf22f.html#ae913dffdd13bd77b79d1a253e88bf22f">VGA_640x350_70HzAlt1</a>);</div><div class="line">  <span class="comment">//DisplayController.setResolution(VGA_640x240_60Hz);    // select to have more free memory</span></div><div class="line"></div><div class="line">  <span class="comment">// Setup mouse</span></div><div class="line">  PS2Controller.<a name="a7"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>();</div><div class="line">  PS2Controller.<a name="a8"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>()-&gt;<a name="a9"></a><a class="code" href="classfabgl_1_1_mouse_a3a139c6e0877d280a65924a0092a7f76.html#a3a139c6e0877d280a65924a0092a7f76">setupAbsolutePositioner</a>(canvas.getWidth(), canvas.getHeight(), <span class="keyword">true</span>, &amp;DisplayController);</div><div class="line">  DisplayController.<a name="a10"></a><a class="code" href="classfabgl_1_1_bitmapped_display_controller_a94fd39f8c9245ed51545f9dd6ce7f6ee.html#a94fd39f8c9245ed51545f9dd6ce7f6ee">setMouseCursor</a>((<a name="a11"></a><a class="code" href="group___enumerations_gab91da6221ce0fc3b24f077fb4b775b2c.html#gab91da6221ce0fc3b24f077fb4b775b2c">CursorName</a>)cursor);</div><div class="line"></div><div class="line">  canvas.setBrushColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div><div class="line">  canvas.clear();</div><div class="line">  canvas.selectFont(&amp;fabgl::FONT_8x8);</div><div class="line">  canvas.setGlyphOptions(GlyphOptions().<a name="a12"></a><a class="code" href="displaycontroller_8h_a4054936031229707e9189e4f2c865e67.html#a4054936031229707e9189e4f2c865e67">FillBackground</a>(<span class="keyword">true</span>));</div><div class="line"></div><div class="line">  showCursorPos(PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>()-&gt;<a name="a13"></a><a class="code" href="classfabgl_1_1_mouse_a13ff5f44b3a7fca9f3e1e8d74242365b.html#a13ff5f44b3a7fca9f3e1e8d74242365b">status</a>());</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  MouseStatus status = PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>()-&gt;<a name="a14"></a><a class="code" href="classfabgl_1_1_mouse_abc9072ef74a767f7b1f39880df870a96.html#abc9072ef74a767f7b1f39880df870a96">getNextStatus</a>(-1); <span class="comment">// -1 = blocking operation</span></div><div class="line"></div><div class="line">  <span class="comment">// left button writes pixels</span></div><div class="line">  <span class="keywordflow">if</span> (status.buttons.left) {</div><div class="line">    canvas.setPenColor(<a name="a15"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1ca2ed18d4ecd62410034c7ff19a1384357">Color::BrightRed</a>);</div><div class="line">    canvas.setPixel(status.X, status.Y);</div><div class="line">    canvas.moveTo(status.X, status.Y);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// right button change mouse shape</span></div><div class="line">  <span class="keywordflow">if</span> (status.buttons.right) {</div><div class="line">    cursor = ((<a class="code" href="group___enumerations_gab91da6221ce0fc3b24f077fb4b775b2c.html#gab91da6221ce0fc3b24f077fb4b775b2c">CursorName</a>)cursor == <a name="a16"></a><a class="code" href="group___enumerations_gab91da6221ce0fc3b24f077fb4b775b2c.html#ggab91da6221ce0fc3b24f077fb4b775b2ca3ad2b2df091b8c2e3afa27bdcbb47eb6">CursorName::CursorTextInput</a> ? 0 : cursor + 1);</div><div class="line">    DisplayController.<a class="code" href="classfabgl_1_1_bitmapped_display_controller_a94fd39f8c9245ed51545f9dd6ce7f6ee.html#a94fd39f8c9245ed51545f9dd6ce7f6ee">setMouseCursor</a>((<a class="code" href="group___enumerations_gab91da6221ce0fc3b24f077fb4b775b2c.html#gab91da6221ce0fc3b24f077fb4b775b2c">CursorName</a>)cursor);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// middle button clear screen</span></div><div class="line">  <span class="keywordflow">if</span> (status.buttons.middle) {</div><div class="line">    canvas.setBrushColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div><div class="line">    canvas.clear();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// mouse wheel moves cursor position indicator</span></div><div class="line">  <span class="keywordflow">if</span> (status.wheelDelta != 0) {</div><div class="line">    indicatorY = fabgl::tclamp(indicatorY + status.wheelDelta, 0, canvas.getHeight() - 16);</div><div class="line">    PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>()-&gt;<a class="code" href="classfabgl_1_1_mouse_a13ff5f44b3a7fca9f3e1e8d74242365b.html#a13ff5f44b3a7fca9f3e1e8d74242365b">status</a>().<a name="a17"></a><a class="code" href="structfabgl_1_1_mouse_status_ac1cf6a18b13ddfb1d9d76322097f3c0f.html#ac1cf6a18b13ddfb1d9d76322097f3c0f">wheelDelta</a> = 0;</div><div class="line">    canvas.setBrushColor(<a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div><div class="line">    canvas.clear();</div><div class="line">  }</div><div class="line"></div><div class="line">  showCursorPos(status);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
